home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Variant Records in C ... Is there a way ?
- Date: Wed, 20 Mar 1996 15:24:08 +0200
- Organization: Carelcomp Products
- Message-ID: <315006F8.639@cmt.lpr.mail.carel.fi>
- References: <Pine.OSF.3.91.960319170252.9783B-100000@alfa.ist.utl.pt>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Nuno Silva wrote:
- >
- > I would like to know if there is any way of implementing in C a
- > structure that if a determined argument (or info or depending on the
- > value of a particular field of a structure) could ignore or acknoledge a
- > certain field of the structure ...
- > [snip]
-
- How about something like:
-
- struct {
- int flag;
- union {
- char text[80];
- int num;
- double fpoint;
- } data;
- } test;
-
- And then, in the code:
-
- switch (test.flag) {
- case FLAG_TEXT:
- /* use test.data.text */
- break;
- case FLAG_NUM:
- /* use test.data.num */
- etc.
- }
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-